#include <QtGui>
#include <QtGui/QApplication>
#include <QMessageBox>
#include "launchermainwindow.h"
#include "filedispatcher.h"

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
        QTextCodec *russianCodec = QTextCodec::codecForName("utf-8");
	QTextCodec::setCodecForTr(russianCodec);

	LauncherMainWindow w;
	w.setWindowTitle(QObject::tr("Launcher System"));
	w.setWindowFlags(Qt::FramelessWindowHint);
	FileDispatcher dsp;
	QObject::connect(&dsp, SIGNAL(allJobsDone()), &a, SLOT(quit()));
	QObject::connect(&dsp, SIGNAL(abnormalExit()), &a, SLOT(quit()));
	QObject::connect(&dsp, SIGNAL(unhandledError(const QString &)), &w, SLOT(unhandledError(const QString &)));
	QObject::connect(&dsp, SIGNAL(fileLoadingStart(const QString &)), &w, SLOT(fileLoadingStart(const QString &)));
	QObject::connect(&dsp, SIGNAL(fileLoadingDone(const QString &)), &w, SLOT(fileLoadingDone(const QString &)));
	QObject::connect(&dsp, SIGNAL(fileSizeInit(int, int)), &w, SLOT(fileSizeInit(int, int)));
	QObject::connect(&dsp, SIGNAL(fileLoadingProgress(int)), &w, SLOT(fileLoadingProgress(int)));
	try
	{
		dsp.loadingProcess();
	}
	catch (QString e)
	{
		QMessageBox::critical(&w, w.windowTitle(), e);
		return 0;
	}
	return a.exec();
}
